package servlet;

import domain.Emp;
import service.EmpUpdateServiceImp;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class EmpUpdateServlet extends HttpServlet {
    EmpUpdateServiceImp empUpdateServiceImp=new EmpUpdateServiceImp();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取保存的所有参数
        String id = request.getParameter("id");
        String ename = request.getParameter("ename");
        String age = request.getParameter("age");
        String sex = request.getParameter("sex");
        String sal = request.getParameter("sal");
        String birthday = request.getParameter("birthday");
        String edate = request.getParameter("edate");
        //设置员工的值
        Emp emp=new Emp();
        emp.setId(Integer.parseInt(id));
        emp.setEname(ename);
        emp.setAge(Integer.parseInt(age));
        emp.setSex(sex);
        emp.setSal(Double.parseDouble(sal));
        emp.setBirthday(birthday);
        emp.setEdate(edate);
        empUpdateServiceImp.updateEmp(emp);
        request.getRequestDispatcher("/empListServlet").forward(request,response);
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           doPost(request,response);
    }
}
